using System.Web.Mvc;
using Microsoft.VisualStudio.TestTools.UnitTesting;
using RecruitmentAgency.Models.DataTypes;
using RecruitmentAgency.Models.Validation;

namespace RecruitmentAgency.Tests.Models.Validation
{
    /// <summary>
    ///This is a test class for CvValidatorTest and contains all CvValidatorTest Unit Tests
    ///</summary>
    [TestClass]
    public class CvValidatorTest
    {
        private ModelStateDictionary modelState;
        private CvValidator target;
        private const string selectMessage = "Please select an option from the list";

        /// <summary>
        ///Initialises test members
        ///</summary>
        [TestInitialize]
        public void Initialize()
        {
            modelState = new ModelStateDictionary();
            target = new CvValidator(modelState, selectMessage);
        }

        /// <summary>
        ///A test for ValidatePersonSkill, passing a PersonSkill in correct form
        ///</summary>
        [TestMethod]
        public void ValidateCorrectPersonSkillTest()
        {
            // expected to pass
            bool expected = true;
            bool actual = target.ValidatePersonSkill(new PersonSkill
            {
                SkillName = "Leadership",
                PersonId = 1,
                PersonSkillId = 12,
                ProficiencyLevel = "Good",
                YearsOfExperience = "3",
            });
            Assert.AreEqual(expected, actual);
        }

        /// <summary>
        ///A test for ValidatePersonSkill, passing a PersonSkill in incorrect form
        ///</summary>
        [TestMethod]
        public void ValidateIncorrectPersonSkillTest()
        {
            // expected to fail
            bool expected = false;
            bool actual = target.ValidatePersonSkill(new PersonSkill
            {
                SkillName = string.Empty,
                PersonId = 1,
                PersonSkillId = 12,
                ProficiencyLevel = selectMessage,
                YearsOfExperience = "three",
            });
            Assert.AreEqual(expected, actual);
            // check that there are 3 validation errors
            Assert.AreEqual(true, modelState.Count == 3);
        }

        /// <summary>
        ///A test for ValidatePersonReferee, passing a PersonReferee in correct form
        ///</summary>
        [TestMethod()]
        public void ValidateCorrectPersonRefereeTest()
        {
            // expected to pass
            bool expected = true;
            bool actual = target.ValidatePersonReferee(new PersonReferee
            {
                RefereeAddressLine1 = "AddressLine1",
                RefereeAddressLine2 = "AddressLine2",
                RefereeTown = "Town",
                RefereePostCode = "PostCode",
                Email = "referee@referees.com",
                Occupation = "Occupation",
                PermissionToContact = true,
                PermissionToStoreDetails = true,
                PersonId = 1,
                RefereePhone = "020 8888 8888",
                RefereeFirstName = "FirstName",
                RefereeId = 3,
                RefereeLastName = "LastName",
                ReferenceText = "ReferenceText",
                Relationship = "Relationship",
                RefereeTitle = "Title",
                YearsKnown = "6"
            });
            Assert.AreEqual(expected, actual);
        }

        /// <summary>
        ///A test for ValidatePersonReferee, passing a PersonReferee in incorrect form
        ///</summary>
        [TestMethod]
        public void ValidateInCorrectPersonRefereeTest()
        {
            // expected to fail
            bool expected = false;
            bool actual = target.ValidatePersonReferee(new PersonReferee
            {
                RefereeAddressLine1 = string.Empty,
                RefereeAddressLine2 = string.Empty,
                RefereeTown = string.Empty,
                RefereePostCode = string.Empty,
                Email = "referee@referees.com.co.uk",
                Occupation = string.Empty,
                PermissionToContact = true,
                PermissionToStoreDetails = true,
                PersonId = 1,
                RefereePhone = "020 8888 8888 shouldn't have letters here",
                RefereeFirstName = string.Empty,
                RefereeId = 3,
                RefereeLastName = string.Empty,
                ReferenceText = string.Empty,
                Relationship = selectMessage,
                RefereeTitle = selectMessage,
                YearsKnown = "six"
            });
            Assert.AreEqual(expected, actual);
            // check that there are 10 validation errors
            Assert.AreEqual(true, modelState.Count == 10);
        }

        /// <summary>
        ///A test for ValidatePersonQualification, passing a PersonQualification in correct form
        ///</summary>
        [TestMethod]
        public void ValidateCorrectPersonQualificationTest()
        {
            // expected to pass
            bool expected = true;
            bool actual = target.ValidatePersonQualification(new PersonQualification
            {
                AwardedBy = "AwardedBy",
                QualificationName = "QualificationName",
                PersonQualificationId = 1,
                PersonId = 1,
                Result = "A",
                Subject = "Subject",
                Type = "A-Level",
                Vocational = false,
                Year = "2001"
            });
            Assert.AreEqual(expected, actual);
        }

        /// <summary>
        ///A test for ValidatePersonQualification, passing a PersonQualification in incorrect form
        ///</summary>
        [TestMethod]
        public void ValidateIncorrectPersonQualificationTest()
        {
            // expected to fail
            bool expected = false;
            bool actual = target.ValidatePersonQualification(new PersonQualification
            {
                AwardedBy = string.Empty,
                QualificationName = string.Empty,
                PersonQualificationId = 1,
                PersonId = 1,
                Result = selectMessage,
                Subject = string.Empty,
                Type = selectMessage,
                Vocational = false,
                Year = "2001 & letters"
            });
            Assert.AreEqual(expected, actual);
            // check that there are 6 validation errors
            Assert.AreEqual(true, modelState.Count == 6);
        }

        /// <summary>
        ///A test for ValidatePersonEmployment, passing a PersonEmployment in correct form
        ///</summary>
        [TestMethod]
        public void ValidateCorrectPersonEmploymentTest()
        {
            // expected to pass
            bool expected = true;
            bool actual = target.ValidatePersonEmployment(new PersonEmployment
            {
                CompanyName = "CompanyName",
                EmploymentId = 1,
                EndDate = "5/5/04",
                IndustrySector = "IndustrySector",
                KeyDuties = "KeyDuties",
                PersonId = 1,
                StartDate = "5/5/99",
                JobTitle = "JobTitle",
            });
            Assert.AreEqual(expected, actual);
        }

        /// <summary>
        ///A test for ValidatePersonEmployment, passing a PersonEmployment in incorrect form
        ///</summary>
        [TestMethod]
        public void ValidateIncorrectPersonEmploymentTest()
        {
            // expected to fail
            bool expected = false;
            bool actual = target.ValidatePersonEmployment(new PersonEmployment
            {
                CompanyName = string.Empty,
                EmploymentId = 1,
                EndDate = "5/5/55",
                IndustrySector = string.Empty,
                KeyDuties = string.Empty,
                PersonId = 1,
                StartDate = "5/5/56",
                JobTitle = string.Empty,
            });
            Assert.AreEqual(expected, actual);
            // check that there are 5 validation errors
            Assert.AreEqual(true, modelState.Count == 5);
        }

        /// <summary>
        ///A test for ValidatePersonalDetail, passing a PersonalDetail in correct form
        ///</summary>
        [TestMethod]
        public void ValidateCorrectPersonalDetailTest()
        {
            // expected to pass
            bool expected = true;
            bool actual = target.ValidatePersonalDetails(new PersonalDetail
            {
                PersonId = 1,
                AddressLine1 = "AddressLine1",
                Town = "Town",
                PostCode = "PostCode",
                AuthorityToWork = "None",
                ContactPreference = "Home phone",
                JobSectorPreference = "Publishing",
                DateOfBirth = "5/5/55",
                Email1 = "someone@somewhere.com",
                Email2 = "someone@somewhere2.com",
                FirstName = "FirstName",
                LastName = "LastName",
                HomePhone = "020 8888 8888",
                MobilePhone = "07980 000 000",
                Sex = Sex.Male,
                Title = "Mr",
                UserName = "hhh",
                WebsiteUrl = "somewhere.com",
                RoleId = 1
            });
            Assert.AreEqual(expected, actual);
        }

        /// <summary>
        ///A test for ValidatePersonalDetail, passing a PersonalDetail in incorrect form
        ///</summary>
        [TestMethod]
        public void ValidateIncorrectPersonalDetailTest()
        {
            // expected to fail
            bool expected = false;
            bool actual = target.ValidatePersonalDetails(new PersonalDetail
            {
                PersonId = 1,
                AddressLine1 = string.Empty,
                Town = string.Empty,
                PostCode = string.Empty,
                AuthorityToWork = selectMessage,
                ContactPreference = "Home phone",
                JobSectorPreference = "Publishing",
                DateOfBirth = "5/5/c55",
                Email1 = "someone@somewhere.com...",
                Email2 = "someone@somewhere2.com...",
                FirstName = string.Empty,
                LastName = string.Empty,
                HomePhone = "020 8888 8888...",
                MobilePhone = "07980 000 000...",
                Sex = Sex.Male,
                Title = selectMessage,
                WebsiteUrl = "somewhere.com...",
            });
            Assert.AreEqual(expected, actual);
            // check that there are 13 validation errors
            Assert.AreEqual(true, modelState.Count == 13);
        }
    }
}